package wiki.zimo.dao;

import wiki.zimo.domain.Category;

/**
 * @version v1.0
 * @auther: 子墨
 * @datetime: 2018/11/1 20:21
 * @description: CategoryDao数据操作类
 */
public class CategoryDao extends BaseDao<Category> {

}
/*public class CategoryDao implements Dao<Category,String> {

	// 获取SQL语句的内部类
	class SQL extends SQLUtils<Category>{

	}
	// 获取SQL语句的对象
	SQL s = new SQL();

	@Override
	public Category insert(Category entity) throws SQLException {
//		String sql = "insert into Category values(? , ?)";
		String sql = s.getInsertSql();
		return qr.insert(sql,
				new BeanHandler<>(Category.class),
				entity.getCid(),
				entity.getCname()
		);
	}

	@Override
	public boolean delete(Category entity) throws SQLException {
//		String sql = "delete from Category where cid = ?";
		String sql = s.getDeleteSql();
		int update = qr.update(sql,
				entity.getCid()
		);
		if (update > 0){
			return true;
		}
		return false;
	}

	@Override
	public Category update(Category entity) throws SQLException {
//		String sql = "update Category set cname = ? where cid = ?";
		String sql = s.getUpdateSql();
		int update = qr.update(sql,
				entity.getCname(),
				entity.getCid()
		);
		if (update > 0){
			return findOneById(entity.getCid());
		}
		return null;
	}

	@Override
	public Category findOneById(String id) throws SQLException {
//		String sql = "select * from Category where cid = ? limit 1";
		String sql = s.getFindOneByIdSql();
		return qr.query(sql, new BeanHandler<>(Category.class), id);
	}

	@SuppressWarnings("NoUse")
	@Override
	public Category findOneByParams(String... params) throws SQLException {
//		String sql = "select * from Category where cid = ? and cname = ? limit 1";
//		return qr.query(sql, new BeanHandler<>(Category.class), params[0], params[1]);
		return null;
	}

	@Override
	public List<Category> findAll() throws SQLException {
//		String sql = "select * from Category";
		String sql = s.getFindAllSql();
		return qr.query(sql,new BeanListHandler<>(Category.class));
	}

	@Override
	public int count() throws SQLException {
		return findAll().size();
	}
}*/
